// components/commentList/commentList.js
const app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    data: {
      type: Object,
      value: {}
    },
    index: {
      type: Number,
      value: 0
    },
    showApprove: {
      type: Boolean,
      value: true
    },
    showAllComment: {
      type: Boolean,
      value: true,
    }
  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    //点击了二级评论
    createCommentAction() {
      this.triggerEvent("twoLevel", { data: this.properties.data, type: "main", index: this.properties.index })
    },
    //回复评论:
    createReplyComment(e) {
      let item = e.currentTarget.dataset.item;
      let subIndex = e.currentTarget.dataset.idx
      this.triggerEvent("threeLevel", { data: item, type: "sub", index: this.properties.index, subIndex: subIndex, id: this.properties.data.id });
    },
    //点赞评论;
    approveComment(e) {
      let index = e.currentTarget.dataset.index;
      this.triggerEvent("approve", { id: this.properties.data.id, index: index });
    },

    //复制职业顾问微信号:
    copyWxChatAction(e) {
      let text = e.currentTarget.dataset.text;
      wx.setClipboardData({
        data: text,
        success: function (res) {
          wx.getClipboardData({
            success: function (res) {
              wx.showToast({
                title: '复制微信号成功'
              })
            },
            fail: function (err) {
              wx.showToast({
                title: '复制失败',
                icon:"none"
              })
            }
          })
        }
      })

    },
    expertChatAction() {
      let item = this.properties.data;
      if (!app.globalData.isLogin) {
        wx.navigateTo({
          url: '/pages/login/login',
        })
        return;
      }
      let chatData = {
        name: item.nickname,
        avatar: item.avatar,
        chatUserId: item.openId,
        conversationType: "C2C",
        expertId: item.id,
        expertPhone: item.phone || "",
        expertWeChat: item.wxChat || "",
      }
      app.globalData.chatData = chatData;
      wx.navigateTo({
        url: '/firstPackage/pages/msgModule/chatRoom/chatRoom',
      })
    },
    expertPhoneAction() {
      console.log("JJLog:data=:" + JSON.stringify(this.properties.data));
      let phone = this.properties.data.phone;
      if (phone) {
        wx.makePhoneCall({
          phoneNumber: phone,
          fail: err => {

          }
        })
      } else {
        wx.showToast({
          title: '暂时无法拨打电话',
          icon: "none"
        })
      }
    },
  }
})
